package com.itheima.jobs;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.service.ClearOrderSettingService;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @PackageName: com.itheima.jobs
 * @ClassName: ClearOrderSetting
 * @Author: WangZhe
 * @Date: 2020/1/6 10:47
 * @Description: //TODO
 */

//自定义job,实现定时清理预约设置数据
@RestController
public class ClearOrderSetting {


    @Reference
    private ClearOrderSettingService clearOrderSettingService;

    //每月最后一天凌晨2点执行一次清理任务,删除三个月前的OrderSetting数据
    public void clearOrderSetting(){
        //1.获取当前时间三个月前的时间
        Date Before = new Date();
        Calendar calendar = Calendar.getInstance(); //得到日历
        calendar.add(calendar.MONTH, -2); //设置为前3月
        Before = calendar.getTime(); //得到前3月的时间

        SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式
        String defaultStartDate = sdf.format(Before); //格式化前3月的时间
        System.out.println(defaultStartDate);
        //2.执行删除命令
        clearOrderSettingService.clearorderSetting(defaultStartDate);


    }


}
